package com.srv.common;

import java.util.HashMap;
import java.util.Map;
import com.srv.util.ObjectField;
import com.srv.util.ObjectFieldDBType;
import com.srv.util.StringUtil;

public class UserField implements ObjectField {
	
	private static Map<String, UserField> map = new HashMap<String, UserField>();
	
	public static final UserField PID = new UserField("PID", ObjectFieldDBType.LONG, false, true);
	public static final UserField ISDEL = new UserField("ISDEL", ObjectFieldDBType.INT, true, false);
	public static final UserField CREATETIME = new UserField("CREATE_TIME", ObjectFieldDBType.TIMESTAMP, true, false);
	public static final UserField UPDATETIME = new UserField("UPDATE_TIME", ObjectFieldDBType.TIMESTAMP, true, false);
	
	public static final UserField SEX = new UserField("SEX", ObjectFieldDBType.INT, false, false);
	
	public static final UserField BIRTHDAY = new UserField("BIRTHDAY", ObjectFieldDBType.TIMESTAMP, false, false);
	
	public static final UserField CITY = new UserField("CITY", ObjectFieldDBType.STRING, true, false);
	
	public static final UserField LASTLOGINTIME = new UserField("LASTLOGIN_TIME", ObjectFieldDBType.TIMESTAMP, true, false);
	
	private String column;
    private ObjectFieldDBType type;
    private boolean modify = false;
    private boolean uniquene = false;
    
    public UserField(String cn, ObjectFieldDBType type, boolean modify, boolean uniquene) {
    	this.column = cn;
        this.type = type;
        this.modify = modify;
        this.uniquene = uniquene;

        map.put(this.column, this);
    }
    
    public String getColumn() {
        return column;
    }

    public ObjectFieldDBType getType() {
        return type;
    }

    public boolean isModify() {
        return modify;
    }

    public boolean isUniquene() {
        return uniquene;
    }

    public int hashCode() {
        return column.hashCode();
    }
    
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof UserField)) {
            return false;
        }

        return column.equalsIgnoreCase(((UserField) obj).getColumn());
    }
    
    public static UserField getByCode(String c) {
        if (StringUtil.isEmpty(c)) {
            return null;
        }

        return map.get(c.toLowerCase());
    }

}
